#include "nodecommand.h"

#include <sstream>
using namespace std;

#include <Poco/DOM/Element.h>
using Poco::XML::Element;

namespace Commands {
	NodeCommand::NodeCommand(NodeData* data, bool need_result) 
		: Command(data ? &(data->origin) : 0, need_result)
		  , _nodeID(data ? data->node_id : 0)
		  , _prevID(data ? data->prev_id : 0)
		  , _nextID(data ? data->next_id : 0)
		  , _ringname(data ? data->ringname : "")
		  , _remote(data ? data->origin : SocketAddress())
		  , _local(data ? data->local : SocketAddress())
		  , _master(data ? data->master : 0)
		  , _port(data ? data->slaveport : 42357)
		  , _node(data ? data->node : 0)
	{
	}

	Document* NodeCommand::toXML(Document * doc)
	{
		Document* d = Command::toXML(doc);
		ostringstream ss; ss << nodeId();
		d->documentElement()->setAttribute("node-id", ss.str());
		return d;
	}
}
